<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<c:set var="jpath" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>用户列表</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0"/>
		<script type="text/javascript">
			window.jQuery || document.write("<script src='${jpath}/static/assets/js/jquery-2.0.3.min.js'>"+"<"+"script>");
		</script>
		<script type="text/javascript">
			if("ontouchend" in document) document.write("<script src='${jpath}/static/assets/js/jquery.mobile.custom.min.js'>"+"<"+"script>");
		</script>
		<script src="${jpath}/static/assets/js/jquery.mobile.custom.min.js"></script>
		<!-- basic styles -->
		<link href="${jpath}/static/assets/css/bootstrap.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="${jpath}/static/assets/css/font-awesome.min.css" />

		<link rel="stylesheet" href="${jpath}/static/assets/css/ace.min.css" />
		<link rel="stylesheet" href="${jpath}/static/assets/css/ace-rtl.min.css" />
		<link rel="stylesheet" href="${jpath}/static/assets/css/ace-skins.min.css" />

	
		<script src="${jpath}/static/assets/js/ace-extra.min.js"></script>
		<script type="text/javascript">
			function prevBtn(nowpageNum,nowpageSize){
				if(nowpageNum>1){	
				loadTbl(nowpageNum-1,nowpageSize);
				}
			}
			function pages(i,nowpageSize){
				loadTbl(i,nowpageSize);
			}
			function nextBtn(nowpageNum,nowpageSize,totalPage){
				if(nowpageNum < totalPage){
					loadTbl(nowpageNum+1,nowpageSize);
				}
			}
			
			function upThis(id){
				$.post("${jpath}/cp/manager/upcpzt",{id:id},function(data){
				var json = $.parseJSON(data);
					alert(json.resMsg);
					if(json.res==1){
						loadTbl(1,4);
				  }
				});
				
				
						
			}
			function editThis(id){
				location.href="${jpath}/updatecp?id="+id;
				$.post("${jpath}/cp/manager/uptadecp",{id:id},function(data){
					var json = $.parseJSON(data);
					alert(json.resMsg);
					if(json.res==1){
						loadTbl(1,4);
					}
				});
			}
			function findhymc(id){
				$.post("${jpath}/cp/manager/findhymc",{id:id},function(data){
					var json = $.parseJSON(data);
					console.log(json.resMsg);
				});
			}
			
			function delThis(id){
				$.post("${jpath}/cp/manager/delcp",{id:id},function(data){
					var json = $.parseJSON(data);
					alert(json.resMsg);
					if(json.res==1){
						loadTbl(1,4);
					}
				});
			}
			function selectAll(){
				var box1=document.getElementById("boxId");
	            //checked判断是否选中
	            if(box1.checked==true)
	            {
			        // 获取要操作的复选框
		            var box1=document.getElementsByName("box");
		            //checked判断是否选中
		            for(var x=0;x<box1.length;x++)
		            {
		                var value1=box1[x];
		                value1.checked=true;
		            }
	            }else{
	                 // 获取要操作的复选框
		            var box2 = document.getElementsByName("box");
		             //checked判断是否选中
		           	for (var x = 0; x < box2.length; x++) {
		               var value1=box2[x];
		               value1.checked=false;
		            }
			    }
			}
			
	
			function loadTbl(nowpageNum,nowpageSize){
				$.post("${jpath}/cp/manager/findByPage",{pageNum:nowpageNum,pageSize:nowpageSize},function(data){
					console.log("000000000000000000000");
					console.log(data);
					var json = $.parseJSON(data);
					if(json.res=="1"){
						var tR = json.obj.totalRecord;
						if(tR > 0){
							$("#fy").show();
							var prevDisabled = "";
							if(nowpageNum==1){
								prevDisabled = "disabled";
							}
							var fyLi='<li class="prev '+prevDisabled+'"><a href="javascript:void(0);" onclick="prevBtn(2,'+nowpageSize+')">';
							fyLi += '第一页</a></li>';
							fyLi +='<li class="prev '+prevDisabled+'"><a href="javascript:void(0);" onclick="prevBtn('+nowpageNum+','+nowpageSize+')">';
							fyLi += '<i class="icon-double-angle-left"></i></a></li>';
							for(var i=1;i<=json.obj.totalPage;i++){
								
								var acStr='';
								if(json.obj.pageNum==i){
									acStr='class="active"';
								}
								if(json.obj.totalPag<=6){
									fyLi+='<li '+acStr+'><a href="javascript:void(0);" onclick="pages('+i+','+nowpageSize+')">'+i+'</li>';
								}else{
									var numPages = nowpageNum-i;
									if(numPages==2){
										fyLi+='<li '+acStr+'><a href="javascript:void(0);">...</li>';
									}else if(numPages<2){
										if(i<=3 || (json.obj.totalPage-i <= 2)){
											fyLi+='<li '+acStr+'><a href="javascript:void(0);" onclick="pages('+i+','+nowpageSize+')">'+i+'</li>';
										}else if(i==4){
											fyLi+='<li '+acStr+'><a href="javascript:void(0);">...</li>';
										}	
									}
								}
								
								
								
							}
							var nextDisabled = "";
							if(nowpageNum==json.obj.totalPage){
								nextDisabled = "disabled";
							}
							fyLi += '<li class="next '+nextDisabled+'"><a href="javascript:void(0);" onclick="nextBtn('+nowpageNum+','+nowpageSize+','+json.obj.totalPage+')">';
							fyLi += '<i class="icon-double-angle-right"></i></a></li>';
							fyLi += '<li class="next '+nextDisabled+'"><a href="javascript:void(0);" onclick="nextBtn('+(json.obj.totalPage-1)+','+nowpageSize+','+json.obj.totalPage+')">';
							fyLi += '最后页</a></li>';
							$("#fy>ul").find("li").remove();
							$("#fy>ul").append(fyLi);
						}
					
						var trStr='';
						var resule = json.obj.results;
						var idd='';
						for(var i=0;i<resule.length;i++){
							console.log("arr="+resule[i].id);
							
							//idd=resule[i].id;
							//findhymc(idd);
							trStr +='<tr><td class="center"><label><input type="checkbox" name="box" id="box1" value="'+resule[i].id+'" class="ace" /><span class="lbl"></span></label></td>';
							trStr +='<td>'+resule[i].id+'</td>';
							trStr +='<td>'+resule[i].bt+'</td>';
							trStr +='<td>'+resule[i].sx+'</td>';
							trStr +='<td>'+resule[i].jj+'</td>';
							//trStr +='<td>${hymc }</td>';
							trStr +='<td>'+resule[i].tj+'</td>';
							trStr +='<td>'+resule[i].lxwm+'</td>';
							trStr +='<td>'+resule[i].hyname+'</td>';
							if(resule[i].cpzt==0){
							trStr +='<td>不通过</td>';
							}else{
								trStr +='<td>通过</td>';
							}
						
							trStr +='<td>'+resule[i].shsj+'</td>';
							trStr +='<td>'+resule[i].yhname+'</td>';
							trStr +='<td>'+resule[i].cpfbsj+'</td>';
							trStr +='<td><div class="btn-group">';
							trStr +='<button class="btn btn-xs btn-info" onclick="editThis(\''+resule[i].id+'\')"><i class="icon-edit bigger-120"></i></button>';
							trStr +='<button class="btn btn-xs btn-danger" onclick="delThis(\''+resule[i].id+'\')"><i class="icon-trash bigger-120"></i></button>';	
							trStr +='<button class="btn btn-xs" onclick="upThis(\''+resule[i].id+'\')">修改状态<i class="icon-trash bigger-120"></i></button></div></td></tr>';	
						}
						$("#sample-table-1>tbody").find("tr").remove();
						$("#sample-table-1>tbody").append(trStr);
					}
				});
				
							
			}
			$(function(){
				loadTbl(1,4);
				$("#add").click(function(){
					location.href="${jpath}/addcp";
				});
				$("#delAll").click(function(){
					var cks = "";
					var c = $("tbody input:checked");
					for(var i =0;i< c.length;i++){
						var d =	c[i].value;
						cks+=d+",";
					}
					//var ss = JSON.stringify(arr);
					//console.log("arr="+arr);
					//console.log("ss="+ss);
					$.post("${jpath}/cp/manager/delAllcp",function(data){
						var json = $.parseJSON(data);
						alert(json.resMsg);
						if(json.res==1){
							loadTbl(1,4);
						}
					});
				});
			});
		</script>

	</head>
  
  <body>
			<div class="table-responsive">
				<table id="sample-table-1" class="table table-striped table-bordered table-hover">
					<thead>
						<tr>
							<th class="center">
								<label>
									<input type="checkbox" id="boxId" onclick="selectAll();" class="ace" />
									<span class="lbl"></span>
								</label>
							</th>
							<th>编号</th>
							<th>标题</th>
							<th>时限</th>
							<th>简介</th>
							<th>条件 </th>
							<th>联系我们</th>
							<th>产品分类</th>
							<th>产品状态</th>
							<th>审核时间</th>
							<th>发布人</th>
							<th>产品发布时间</th>
							
							<th></th>
						</tr>
					</thead>

					<tbody>
						
						
					</tbody>
				</table>
				
			</div><!-- /.table-responsive -->
			
			
			<div class="modal-footer no-margin-top" style="display:none" id="fy">

				<ul class="pagination pull-right no-margin">
					
				</ul>
			</div>
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-app btn-primary btn-sm" id="add" type="button">
						<i class="icon-edit bigger-230"></i>
						添加产品
					</button>
	
					<button style="width:198px;" class="btn btn-app btn-danger btn-sm" id="delAll" type="button">
						<i class="icon-trash bigger-200"></i>
						删除审核未通过的产品
					</button>
				</div>
			</div>
		
  </body>
</html>
